package cn.edu.hbsi.web.controller;

import cn.edu.hbsi.domain.dto.NewsPageDTO;
import cn.edu.hbsi.domain.result.PageResult;
import cn.edu.hbsi.domain.result.Result;
import cn.edu.hbsi.domain.vo.TypeVO;
import cn.edu.hbsi.service.HeadlineService;
import cn.edu.hbsi.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 首页模块
 */
@RestController
@RequestMapping("/portal")
@Slf4j
@Api(tags = "首页模块相关接口")
public class PortalController
{
    @Autowired
    private TypeService typeService;

    @Autowired
    private HeadlineService headlineService;

    /**
     * 查询所有新闻类型
     * @return
     */
    @ApiOperation("查询所有新闻类型")
    @GetMapping("/findAllTypes")
    public Result<TypeVO> findAllTypes(){
        return typeService.findAllTypes();
    }

    /**
     * 查询新闻分页数据
     * @param newsPageDTO
     * @return
     */
    @ApiOperation("查询新闻分页数据")
    @PostMapping("/findNewsPage")
    public Result findNewsPage(@RequestBody NewsPageDTO newsPageDTO){
        log.info("查询新闻分页数据：{}", newsPageDTO);
        return headlineService.findNewsPage(newsPageDTO);
    }

    /**
     * 查询头条详情
     * @param hid
     * @return
     */
    @ApiOperation("查询头条详情")
    @PostMapping("/showHeadlineDetail")
    public Result showHeadlineDetail(@RequestParam("hid") Integer hid){
        log.info("查询头条详情：{}",hid);
        return headlineService.showHeadlineDetail(hid);
    }
}
